package xyz.fuqufyb.aec.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import xyz.fuqufyb.aec.dao.ApiMappingMapper;
import xyz.fuqufyb.aec.data.TableResult;
import xyz.fuqufyb.aec.entity.ApiMapping;
import xyz.fuqufyb.aec.service.IApiMappingService;

import java.util.List;
import java.util.Map;

/**
 * @author 用户: fyb
 * @description class: ApiMappingServiceImpl
 * @date 时间: 2021/2/2 16:40
 */
@Service("IApiMappingService")
public class ApiMappingServiceImpl implements IApiMappingService {

    @Autowired
    private ApiMappingMapper apiMappingMapper;

    @Override
    public int deleteByPrimaryKey(Integer id) {
        int i = apiMappingMapper.deleteByPrimaryKey(id);

        if (i > 0) {
            return i;
        }
        return 0;
    }

    @Override
    public int insertSelective(ApiMapping record) {

        int i = apiMappingMapper.insertSelective(record);
        if (i > 0) {

            return i;
        }
        return 0;
    }

    @Override
    public ApiMapping selectByPrimaryKey(Integer id) {
        ApiMapping apiMapping = apiMappingMapper.selectByPrimaryKey(id);

        if (apiMapping != null) {
            return apiMapping;

        }
        return null;
    }

    @Override
    public int updateByPrimaryKeySelective(ApiMapping record) {

        int i = apiMappingMapper.updateByPrimaryKeySelective(record);

        if (i > 0) {

            return i;
        }
        return 0;
    }

    @Override
    public TableResult getPageApiMapping(Map<String, Object> maps) {
        String page = (String) maps.get("page");

        String limit = (String) maps.get("limit");

        if (page != null && limit != null) {

            PageHelper.startPage(Integer.parseInt(page), Integer.parseInt(limit));

            List<ApiMapping> pageApiMapping = apiMappingMapper.getPageApiMapping(maps);

            PageInfo<ApiMapping> pageInfo = new PageInfo<>(pageApiMapping);

            return TableResult.getTableResultSuccess(pageInfo.getTotal(), pageInfo.getList());

        }

        return TableResult.getTableResultError("参数不能为空");
    }

    @Override
    public int delApiMappingIds(List<Integer> asList) {

        int i = apiMappingMapper.delApiMappingIds(asList);

        return 0;
    }
}
